//
//  CommonStudyLinkHeaderView.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/3.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "CommonStudyLinkHeaderView.h"

@interface CommonStudyLinkHeaderView ()

/**  底层的图片  */
@property (strong, nonatomic) UIImageView  *backImageView;
/**  头像图片  */
@property (strong, nonatomic) UIImageView  *headImageView;
/**  名字  */
@property (strong, nonatomic) UILabel  *nameLabel;


@end
/**  220  */
@implementation CommonStudyLinkHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self layoutUI];
    
    }
    return self;
}




#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.backImageView];
    [self addSubview:self.headImageView];
    [self addSubview:self.nameLabel];
    
    self.backImageView.sd_layout
    .topEqualToView(self)
    .leftEqualToView(self)
    .widthIs([UIScreen zj_screenWith])
    .heightIs(150 * [UIScreen zj_screenHScale]);
    
    self.headImageView.sd_layout
    .centerXIs(self.centerX)
    .heightIs(70 * [UIScreen zj_screenHScale])
    .widthIs(70 * [UIScreen zj_screenHScale])
    .topSpaceToView(self,105 * [UIScreen zj_screenHScale]);
    
    self.nameLabel.sd_layout
    .leftEqualToView(self)
    .widthIs([UIScreen zj_screenWith])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .topSpaceToView(self.headImageView,7 * [UIScreen zj_screenHScale]);
    
    
    UIView *under = [UIView new];
    under.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:under];
    under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1.5);
    
}



#pragma mark - getter


- (void)setModel:(LpRankingPersonModel *)model{
    _model = model;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.PHOTO_URL]] placeholderImage:PlaceholderHeaderImage];
    if (self.isName == YES) {
        self.nameLabel.text = model.USER_NAME;
    }else{
        self.nameLabel.text =[NSString stringWithFormat:@"%@占领了封面", model.USER_NAME];
    }
    
}
- (UIImageView *)backImageView{
    if (!_backImageView ) {
        _backImageView = [UIImageView new];
        _backImageView.image = [UIImage imageNamed:@"mine_bg"];
        _backImageView.contentMode = UIViewContentModeScaleToFill;
        
    }
    return _backImageView;
}

- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [UIImageView new];
        _headImageView.layer.cornerRadius = 35 * [UIScreen zj_screenHScale];
        _headImageView.layer.masksToBounds = YES;
    }
    return _headImageView;
    
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _nameLabel;
}


@end
